import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { ClassType, VideosType, VideosValueType } from 'src/redux/types';

export interface movieSource {
  class: Array<ClassType>;
  videos: VideosType;
}

export const initialState: movieSource = {
  class: [],
  videos: {
    value: [],
    attr: {
      page: 1,
      pagecount: 0,
      pagesize: 0,
      recordcount: 0,
    },
  },
};

export const MovieSlice = createSlice({
  name: 'movie',
  initialState,
  reducers: {
    setClass(state, action: PayloadAction<Array<ClassType>>) {
      return { ...state, class: action.payload };
    },
    setVideos(state, action: PayloadAction<VideosType>) {
      return { ...state, videos: action.payload };
    },
    clearVideosValue(state) {
      return { ...state, videos: { ...state.videos, value: [] } };
    },
  },
});

export const actions = MovieSlice.actions;
